package com.ruoyi.service.impl;

import java.util.List;

import com.ruoyi.domain.AdvPlatinfos;
import com.ruoyi.mapper.AdvPlatinfosMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.AdvInfoliksMapper;
import com.ruoyi.domain.AdvInfoliks;
import com.ruoyi.service.IAdvInfoliksService;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-03
 */
@Service
public class AdvInfoliksServiceImpl implements IAdvInfoliksService
{
    @Autowired
    private AdvInfoliksMapper advInfoliksMapper;
    @Autowired
    private AdvPlatinfosMapper advPlatinfosMapper;

    /**
     * 查询
     *
     * @param advInfoliksId 主键
     * @return
     */
    @Override
    public AdvInfoliks selectAdvInfoliksByAdvInfoliksId(Long advInfoliksId)
    {
        return advInfoliksMapper.selectAdvInfoliksByAdvInfoliksId(advInfoliksId);
    }

    /**
     * 查询列表
     *
     * @param advInfoliks
     * @return
     */
    @Override
    public List<AdvInfoliks> selectAdvInfoliksList(AdvInfoliks advInfoliks)
    {
        return advInfoliksMapper.selectAdvInfoliksList(advInfoliks);
    }

    /**
     * 新增
     *
     * @param advInfoliks
     * @return 结果
     */
    @Override
    public int insertAdvInfoliks(AdvInfoliks advInfoliks)
    {
        return advInfoliksMapper.insertAdvInfoliks(advInfoliks);
    }

    /**
     * 修改
     *
     * @param advInfoliks
     * @return 结果
     */
    @Override
    public int updateAdvInfoliks(AdvInfoliks advInfoliks)
    {
        return advInfoliksMapper.updateAdvInfoliks(advInfoliks);
    }

    /**
     * 批量删除
     *
     * @param advInfoliksIds 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteAdvInfoliksByAdvInfoliksIds(Long[] advInfoliksIds)
    {
        return advInfoliksMapper.deleteAdvInfoliksByAdvInfoliksIds(advInfoliksIds);
    }

    /**
     * 删除信息
     *
     * @param advInfoliksId 主键
     * @return 结果
     */
    @Override
    public int deleteAdvInfoliksByAdvInfoliksId(Long advInfoliksId)
    {
        return advInfoliksMapper.deleteAdvInfoliksByAdvInfoliksId(advInfoliksId);
    }

    @Override
    @Transactional
    public int doGood(AdvInfoliks advInfoliks) {
        int i = advInfoliksMapper.insertAdvInfoliks(advInfoliks); // 往点赞表中添加数据
        int y = advPlatinfosMapper.goodUp(advInfoliks.getAdvPlatinfosId());
        return i+y;
    }

    @Override
    @Transactional
    public int canceGood(AdvInfoliks advInfoliks) {
        int i = advInfoliksMapper.cancelGood(advInfoliks.getAdvPlatinfosId(), advInfoliks.getAdvMembersId()); // 往点赞表中删除数据
        int y = advPlatinfosMapper.goodDown(advInfoliks.getAdvPlatinfosId());
        return i+y;
    }
}
